﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;

namespace TushuGuan_GUI
{
    public class BookBorrowed
    {
        int banben = 1;
        //图书编号
        public string ISBN { get; set; }
        /// <summary>
        /// 借书时间
        /// </summary>
        public DateTime Time { get; set; }
        /// <summary>
        /// 期限 单位 天
        /// </summary>
        public int Lasttime { get; set; }
        public string Save()
        {
            string data = new JObject(
                      new JProperty("banben", banben),
                      new JProperty("ISBN", ISBN),
                      new JProperty("Time", Time.ToBinary()),
                      new JProperty("Lasttime", Lasttime)).ToString();
            return data;
        }
        public void Load(string data)
        {
            var json = (JObject)JsonConvert.DeserializeObject(data);
            switch (int.Parse(json["banben"].ToString()))
            {
                case 1:
                    Load_1(data);
                    break;
                default:
                    return;
            }
        }
        private void Load_1(string data)
        {
            var json = (JObject)JsonConvert.DeserializeObject(data);
            var ISBN = json["ISBN"];
            var Time = json["Time"];
            var Lasttime = json["Lasttime"];

            //保存结果

            this.ISBN = ISBN.ToString();
            this.Time = DateTime.FromBinary(long.Parse(Time.ToString()));
            this.Lasttime = int.Parse(Lasttime.ToString());

        }


    }
}
